<?php
	

class ArclistModel extends Model{

	protected $tableName = 'arclist'; 



    // 删除单项信息
    public function delonelist($id){
        $map['id'] = $id;
        $mid = $this->where($map)->getField('mid');
        if(!$mid){
            return false;
        }
        $table = D('Model')->gettable($mid);
        $del = $this->where($map)->delete();
        if($del){
            D($table)->where('aid ='.$id)->delete();
            return true;
        }else{
            return false;
        }
    }

    // 删除多项信息
	public function delmorelist($arr){
        foreach($arr as $k => $v){
            $del =  $this->delonelist($v);
            if(!$del){
                return false;
            }
        }
        return true;
    }


    public function getInfo($id){
       $map['id']  =$id;
       $info  = D('Arclist')->where($map)->find();  //基本数据参数
       $mid   = D('Column')->getMid($info['cid']);   
       $minfo = D('Model')->where('mid ='.$mid)->find();  // 获取模型数据
       $info2 = D($minfo['table'])->where('aid ='.$map['id'])->find(); // 获取辅助表数据
       $data  = ($info2)?array_merge($info,$info2):$info; // 合并整个数据
       return $data;
    }

    public function addActiondata($postinfo){

       $commonarray = array('cid','mid','title','keyword','description','images','click','old_price','price','iscommend','sendtime','updatetime','sort','fid','tid');
        $nohtmlarray = array('content','service');
        $commondata['mid'] = D('Column')->getMid($postinfo['cid']);
        foreach($postinfo as $k => $v){
            if(in_array($k,$commonarray)){
                $commondata[$k]   = $postinfo[$k];
            }else{
                if(in_array($k,$nohtmlarray)){
                    $infodata[$k] = $_POST[$k];
                }else{
                    $infodata[$k] = $postinfo[$k];
                }
            }
        }
        $commondata['sendtime']     = time();
        $commondata['updatetime']   = $commondata['sendtime'];



        return array('commondata'=>$commondata,'infodata'=>$infodata);
    }

}

?>